home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tex / docstrip.tex < prev    next >
Encoding:
Text File  |  1991-11-27  |  14.6 KB  |  546 lines

  1. %% This is file `docstrip.tex' generated
  2. %% on <1991/2/1> with the docstrip utility (v1.1l test). 
  3. %% 
  4. %% The original source file was `docstrip.doc'.
  5. %% Included modules: `stats'.
  6. %% 
  7. %% IMPORTANT NOTICE:
  8. %% You are not allowed to distribute this file.
  9. %% For distribution of the original source see 
  10. %% the copyright notice in the file `docstrip.doc'. 
  11. %% 
  12. \def\filename{docstrip}
  13. \def\fileversion{v1.1l test}
  14. \def\filedate{90/12/10}
  15. \def\docdate {90/06/15}
  16.  
  17. %% \CheckSum{835}
  18. %% \CharacterTable
  19. %%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  20. %%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
  21. %%   Digits        \0\1\2\3\4\5\6\7\8\9
  22. %%   Exclamation   \!     Double quote  \"     Hash (number) \#
  23. %%   Dollar        \$     Percent       \%     Ampersand     \&
  24. %%   Acute accent  \'     Left paren    \(     Right paren   \)
  25. %%   Asterisk      \*     Plus          \+     Comma         \,
  26. %%   Minus         \-     Point         \.     Solidus       \/
  27. %%   Colon         \:     Semicolon     \;     Less than     \<
  28. %%   Equals        \=     Greater than  \>     Question mark \?
  29. %%   Commercial at \@     Left bracket  \[     Backslash     \\
  30. %%   Right bracket \]     Circumflex    \^     Underscore    \_
  31. %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
  32. %%   Right brace   \}     Tilde         \~}
  33. %%
  34. \nofiles
  35.  
  36. \makeatletter
  37.  
  38.  
  39. %% correcting a LaTeX bug first...
  40. \def\@xtypein[#1]#2{\typeout{#2}\read\sixt@@n to#1\ifx #1\@defpar
  41.   \def#1{}\else
  42.    \@iden{\expandafter\@strip\expandafter
  43.    #1#1\@gobble\@gobble} \@gobble\fi\@typein}
  44.  
  45. \typeout{LaTeX utility: `docstrip'
  46.    \fileversion\space <\filedate> (FMi)}
  47. \typeout{English documentation
  48.  \@spaces\@spaces\space\space <\docdate> (FMi)}
  49. \typeout{}
  50. \typeout{**********************************************************}
  51. \typeout{* This program converts documented macro-files into fast *}
  52. \typeout{* loadable files by stripping of (nearly) all comments!
  53.                                                             \space*}
  54. \typeout{**********************************************************}
  55. \typeout{}
  56.  
  57. \def\test@batchfile{%
  58.   \ifx\undefined\batchfile
  59.     \let\batchfile\default@batchfile
  60.     \@okaytrue \else \@okayfalse \fi
  61.   \openin\batch@stream \batchfile\relax
  62.   \ifeof\batch@stream
  63.     \if@okay \else
  64.       \typeout{*************************************************}
  65.       \typeout{* Could not find your \string\batchfile=\batchfile}
  66.       \typeout{* Try to continue without it}
  67.       \typeout{*************************************************}
  68.     \fi
  69.   \else
  70.     \if@okay
  71.       \typeout{*************************************************}
  72.       \typeout{* Batch file docstrip.cmd found. Use it ? (y/n) *}
  73.       \typein[\answer]
  74.               {*************************************************}
  75.       \def\@tempa{y}%
  76.     \else \let\answer\@tempa \fi
  77.     \ifx\@tempa\answer \process@batchfile \fi
  78.   \fi}
  79.  
  80. \def\ask@questions{%
  81.    \typeout{}
  82.    \typeout{***************************************************}
  83.    \typeout{* First type the extension of your input file(s): *}
  84.    \typein[\infileext]
  85.            {***************************************************}
  86.    \typeout{}
  87.    \typeout{**************************************************}
  88.    \typeout{* Now type the extension of your output file(s): *}
  89.    \typein[\outfileext]
  90.            {**************************************************}
  91.    \typeout{}
  92.    \typeout{**************************************************}
  93.    \typeout{* Now give the name(s) of module(s) to include: \space *}
  94.    \typein[\includelist]
  95.            {**************************************************}
  96.    \typeout{}
  97.    \typeout{**************************************************}
  98.    \typeout{* Finally give the list of input file(s) without *}
  99.    \typeout{* extension separated by commas if necessary:\@spaces*}
  100.    \typein[\filelist]
  101.            {**************************************************}}
  102.  
  103. \newif\if@okay
  104. \newread\@infile
  105. \newread\@outfile
  106.  
  107. \def^^L{ }
  108.  
  109. \def\set@filenames{%
  110.     \edef\in@filename{\main@filename.\infileext}%
  111.     \edef\out@filename{\main@filename.\outfileext}}
  112.  
  113. \def\check@filenames{%
  114.   \ifx\infileext\outfilext
  115.     \typeout{}
  116.     \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  117.     \typeout{! Not possible to read from and write to the same file !}
  118.     \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  119.     \@okayfalse
  120.   \else
  121.     \@okaytrue
  122.     \immediate\openin\@infile \in@filename \relax
  123.     \ifeof \@infile
  124.       \@okayfalse
  125.       \typeout{}
  126.       \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  127.       \typeout{! Input file `\in@filename' not found !}
  128.       \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  129.     \else
  130.       \check@outfile
  131.     \fi
  132.     \immediate\closein\@infile
  133.   \fi}
  134.  
  135. \def\check@outfile{%
  136.    \immediate\openin\@outfile \out@filename \relax
  137.    \ifeof \@outfile \@okaytrue
  138.    \else
  139.      \@okayfalse
  140.      \typeout{}
  141.      \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  142.      \typeout{! Output file `\out@filename' already exists.}
  143.      \typeout{! Do you want to overwrite it? (yes/no)}
  144.      \typein[\answer]{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  145.      \def\@tempa{yes}%
  146.      \ifx\answer\@tempa \@okaytrue \fi
  147.     \fi
  148.     \immediate\closein\@outfile}
  149.  
  150. \def\write@postamble{%
  151.     \owrite{\string\endinput}%
  152.     \owrite{\double@percent}%
  153.     \owrite{\double@percent End of file `\out@filename'.}%
  154.     \immediate\closeout\@outfile}
  155.  
  156.   \newcount\numberof@files
  157.   \newcount\meta@comment
  158.   \newcount\normal@comment
  159.   \newcount\code@line
  160.   \newcount\processed@line
  161.   \newcount\summeta@comment
  162.   \newcount\sumnormal@comment
  163.   \newcount\sumcode@line
  164.   \newcount\sumprocessed@line
  165.  
  166. \def\process@line{%
  167.   \advance\processed@line\@ne
  168.     \futurelet\next\process@@line}
  169.  
  170. \begingroup
  171. \catcode`\*=12
  172. \lccode`\*=`\%
  173. \lowercase{%
  174. \gdef\double@percent{** }
  175. \gdef\percent@{*}
  176. \gdef\process@@line{%
  177.     \if*\next
  178.       \expandafter\check@second
  179.     \else
  180.   \advance\code@line\@ne
  181.   \endlast@module
  182.            \expandafter\put@line
  183.     \fi}
  184. \gdef\check@@second{%
  185.   \if*\next
  186.  \advance\meta@comment\@ne
  187.  \endlast@module
  188.           \let\next\put@line
  189.    \else
  190.     \if<\next
  191.       \let\next\check@module
  192.     \else
  193.  \advance\normal@comment\@ne
  194.  \endlast@module
  195.       \let\next\remove@line
  196.     \fi
  197.   \fi
  198.   \next}
  199. }
  200.  
  201. \endgroup
  202.  
  203. \gdef\check@second#1{\futurelet\next\check@@second}
  204.  
  205. \def\check@module<{\futurelet\next\check@@module}
  206.  
  207. \def\check@@module{%
  208.     \if+\next
  209.      \let\next\plus@module
  210.     \else
  211.       \if-\next
  212.         \let\next\minus@module
  213.       \else
  214.         \if*\next
  215.           \let\next\star@module
  216.         \else
  217.           \if/\next
  218.             \let\next\slash@module
  219.          \else
  220.             \advance\normal@comment\@ne
  221.             \endlast@module
  222.             \let\next\remove@line
  223.           \fi
  224.         \fi
  225.       \fi
  226.     \fi
  227.     \next}
  228.  
  229. \def\module@included#1#2{%
  230.    \ifin@line@module
  231.      \def\@tempa{#1#2}%
  232.      \ifx\@tempa\curr@module \else
  233.      \maybe@message{>}\in@line@modulefalse \module@included#1{#2}\fi
  234.    \else
  235.      \in@line@moduletrue
  236.      \def\curr@module{#1#2}%
  237.      \maybe@message{<#1#2}%
  238.       \inclcurr@modulefalse
  239.       \@for\@tempa:=#2\do
  240.       {\edef\@tempb{\noexpand\in@{\@tempa,}{\includelist,}}%
  241.       \@tempb \ifin@ \inclcurr@moduletrue \fi}%
  242.     \fi
  243. }
  244.  
  245. \def\endlast@module{%
  246.    \ifin@line@module
  247.      \maybe@message{>}\in@line@modulefalse \fi}
  248.  
  249.  \newif\ifin@line@module
  250. \newif\ifinclcurr@module
  251.  
  252. \def\plus@module+#1>{%
  253.   \module@included+{#1}%
  254.   \ifinclcurr@module
  255.  \advance\code@line\@ne
  256.           \expandafter\put@module
  257.   \else
  258.  \advance\normal@comment\@ne
  259.           \expandafter\remove@line
  260.   \fi}
  261.  
  262. \newif\ifoutput@block \output@blocktrue
  263. \newif\ifin@block
  264.  
  265. \def\star@module*#1>{%
  266.  \ifin@block
  267.   \errmessage{Already in block <\block@type>}%
  268.  \else
  269.   \in@blocktrue
  270.   \def\block@type{*#1}%
  271.   \module@included*{#1}%
  272.   \in@line@modulefalse
  273.   \ifinclcurr@module
  274.     \output@blocktrue
  275.   \else
  276.     \output@blockfalse
  277.   \fi
  278.  \fi
  279.  \advance\normal@comment\@ne
  280.  \remove@line
  281. }
  282.  
  283. \def\slash@module/#1>{%
  284.  \ifin@block
  285.   \in@blockfalse
  286.   \output@blocktrue
  287.  \maybe@message{\percent@}%
  288.  \maybe@message{>}%
  289.   \def\@tempa{*#1}%
  290.   \ifx\@tempa\block@type
  291.   \else
  292.     \errmessage{Block <\block@type> ended by </#1>}%
  293.   \fi
  294.  \else
  295.   \errmessage{There was no start block for </#1>}%
  296.  \fi
  297.  \advance\normal@comment\@ne
  298.  \remove@line
  299. }
  300.  
  301. \def\minus@module-#1>{%
  302.   \module@included-{#1}%
  303.   \ifinclcurr@module
  304.  \advance\normal@comment\@ne
  305.           \expandafter\remove@line
  306.   \else
  307.  \advance\code@line\@ne
  308.           \expandafter\put@module
  309.   \fi}
  310.  
  311. \def\in@#1#2{%
  312.   \def\in@@##1#1##2##3\in@@{%
  313.     \ifx\in@##2\in@false\else\in@true\fi}%
  314.   \in@@#2#1\in@\in@@}
  315.  
  316. \newif\ifin@
  317.  
  318. \def\include#1{\def\includelist{#1}}
  319.  
  320. \include{}
  321.  
  322. \def\owrite{%
  323.  \maybe@message{.}%
  324.   \immediate\write\@outfile}
  325.  
  326. \let\end@inline\relax
  327.  
  328. \def\put@module#1\end@inline{\owrite{#1}}
  329.  
  330. \def\put@line#1\end@inline{%
  331.   \ifoutput@block
  332.      \owrite{\in@line}%
  333.  \else
  334.    \maybe@message{\percent@}%
  335.   \fi
  336. }
  337.  
  338. \def\remove@line#1\end@inline{%
  339.  \maybe@message{\percent@}%
  340. }
  341.  
  342. \def\setup@reading{%
  343.        \immediate\openin\@infile \in@filename \relax
  344.        \@sanitize
  345.        \@makeother\{%
  346.        \@makeother\}%
  347.        \endlinechar\m@ne
  348.        \par@cnt\z@}
  349.  
  350. \edef\end@input{\expandafter\@gobble\string\\endinput}
  351.  
  352. \newcount\par@cnt
  353.  
  354. \def\process@file{%
  355.   \typeout{}%
  356.   \typeout{Processing \in@filename\space
  357.            \ifx\includelist\@empty \else
  358.             (\includelist) \fi
  359.             -> \out@filename}%
  360.   \typeout{}%
  361.   \begingroup
  362.   \setup@reading
  363.   \loop
  364.     \read\@infile to\in@line
  365.     \ifx\end@input\in@line
  366.       \typeout{File \in@filename\space
  367.                ended by \string\endinput.}%
  368.       \@tempswafalse                      % end the loop
  369.     \else
  370.       \ifx\@empty\in@line
  371.         \advance\par@cnt\@ne
  372.       \else
  373.         \par@cnt\z@
  374.       \fi
  375.       \ifnum \par@cnt<2
  376.         \expandafter\process@line\in@line\end@inline
  377.       \else
  378.         \maybe@message{/}%
  379.       \fi
  380.       \ifeof\@infile \@tempswafalse \else \@tempswatrue \fi
  381.     \fi
  382.   \if@tempswa
  383.   \repeat
  384.   \immediate\closein\@infile
  385.     \typeout{Lines \space processed: \the\processed@line}
  386.     \typeout{Comments removed: \the\normal@comment}
  387.     \typeout{Comments \space passed: \the\meta@comment}
  388.     \typeout{Codelines passed: \the\code@line}
  389.     \global\advance\sumprocessed@line\processed@line
  390.     \global\advance\sumnormal@comment\normal@comment
  391.     \global\advance\summeta@comment\meta@comment
  392.     \global\advance\sumcode@line\code@line
  393.     \global\advance\numberof@files\@ne
  394.  \endgroup}
  395.  
  396. \def\generatefile#1#2#3{%
  397.  \def\out@filename{#1}%
  398.  \typeout{}%
  399.  \typeout{Generating \out@filename:}%
  400.  \typeout{}%
  401.  \if#2t\check@outfile\else\@okaytrue\fi
  402.  \if@okay
  403.    \def\from##1##2{\owrite{\double@percent ##1
  404.                    \if!##2!\else \space
  405.                     (with modules: `##2')\fi}}%
  406.    \edef\reference@lines{\owrite{\double@percent }%
  407.        \owrite{\double@percent The original source files were:}%
  408.        \owrite{\double@percent }%
  409.        #3}%
  410.     \def\from##1##2{\def\in@filename{##1}%
  411.                     \def\includelist{##2}%
  412.                     \process@file}%
  413.     \write@preamble#3\write@postamble
  414.     \let\reference@lines\original@refs
  415.  \fi}
  416.  
  417. \def\processfile#1#2#3#4{%
  418.    \def\main@filename{#1}%
  419.    \def\infileext{#2}%
  420.    \def\outfileext{#3}%
  421.    \set@filenames
  422.    \if #4t\check@filenames\fi
  423.    \if@okay
  424.      \write@preamble
  425.      \process@file
  426.      \write@postamble
  427.    \else \@okaytrue \fi}
  428.  
  429. \def\write@preamble{%
  430.   \immediate\openout\@outfile \out@filename \relax
  431.   \owrite{\double@percent This is file `\out@filename' generated}%
  432.   \owrite{\double@percent on <\the\year/\the\month/\the\day> with
  433.                           the docstrip utility (\fileversion). }%
  434.   \reference@lines
  435.   \owrite{\double@percent IMPORTANT NOTICE:}%
  436.   \owrite{\double@percent You are not allowed to distribute this file.}%
  437.   \owrite{\double@percent For distribution of the original source see }%
  438.   \owrite{\double@percent the copyright notice in the file `\in@filename'. }%
  439.   \owrite{\double@percent }}
  440.  
  441. \def\original@refs{%
  442.   \owrite{\double@percent }%
  443.   \owrite{\double@percent The original source file was `\in@filename'.}%
  444.   \ifx\includelist\@empty\else
  445.     \owrite{\double@percent Included modules: `\includelist'.}\fi
  446.   \owrite{\double@percent }}
  447.  
  448. \let\reference@lines\original@refs
  449.  
  450. \def\default@batchfile{docstrip.cmd}
  451.  
  452.  
  453. \def\showprogress{\let\maybe@message\message}
  454. \def\keepsilent{\let\maybe@message\@gobble}
  455.  
  456. \def\preamble{\begingroup
  457.   \let\reference@lines\relax
  458.   \let\out@filename\relax
  459.   \let\in@filename\relax
  460.   \@tempswatrue
  461.   \def\@tempa{\endpreamble}%
  462.   \def\@tempb{\par}%
  463.   \gdef\write@preamble{%
  464.      \immediate\openout\@outfile \out@filename \relax
  465.      \owrite{\double@percent }%
  466.      \owrite{\double@percent This is file `\out@filename' generated}%
  467.      \owrite{\double@percent on <\the\year/\the\month/\the\day> with
  468.                              the docstrip utility (\fileversion). }%
  469.      \reference@lines}%
  470.   \loop
  471.      \read\batch@stream to \batch@line   % get stuff for preamble
  472.      \ifx\batch@line\@tempa \@tempswafalse \else
  473.         \xdef\write@preamble{\write@preamble\owrite
  474.                {\double@percent
  475.                 \ifx\batch@line\@tempb\else\batch@line\fi}}\fi
  476.   \if@tempswa
  477.   \repeat\endgroup}
  478.  
  479. \def\postamble{\begingroup
  480.   \@tempswatrue
  481.   \def\@tempa{\endpostamble}%
  482.   \def\@tempb{\par}%
  483.   \gdef\write@postamble{}%
  484.   \loop
  485.      \read\batch@stream to \batch@line   % get stuff for postamble
  486.      \ifx\batch@line\@tempa \@tempswafalse \else
  487.         \xdef\write@postamble{\write@postamble\owrite
  488.                {\double@percent
  489.                 \ifx\batch@line\@tempb\else\batch@line\fi}}\fi
  490.   \if@tempswa
  491.   \repeat\endgroup
  492.   \xdef\write@postamble{\write@postamble
  493.                  \immediate\closeout\@outfile}}
  494.  
  495. \newif\ifmore@files \more@filestrue
  496.  
  497. \newread\batch@stream
  498.  
  499. \def\process@batchfile{%
  500.   \@okaytrue
  501.   \let\endinput\@okayfalse
  502.   \loop
  503.   \ifeof\batch@stream \@okayfalse \else
  504.     \read\batch@stream to \batch@line         % get input line
  505.     \batch@line
  506.   \fi
  507.   \if@okay
  508.   \repeat
  509.   \more@filesfalse}
  510.  
  511.  
  512. \showprogress
  513.  
  514. \test@batchfile
  515.  
  516.   \@whilesw\ifmore@files\fi
  517.     {\ask@questions
  518.      \@for\main@filename:=\filelist \do
  519.        {\set@filenames
  520.         \check@filenames
  521.         \if@okay
  522.            \write@preamble
  523.            \process@file
  524.            \write@postamble
  525.         \fi}%
  526.      \typein[\answer]{More files to process? (yes/no)}
  527.      \def\@tempa{yes}%
  528.      \ifx\answer\@tempa \else \more@filesfalse \fi}
  529.  
  530.   \typeout{}
  531.   \ifnum\numberof@files>\@ne
  532.     \typeout{Overall statistics:}
  533.     \typeout{Files \space processed: \the\numberof@files}
  534.     \typeout{Lines \space processed: \the\sumprocessed@line}
  535.     \typeout{Comments removed: \the\sumnormal@comment}
  536.     \typeout{Comments \space passed: \the\summeta@comment}
  537.     \typeout{Codelines passed: \the\sumcode@line}
  538.   \fi
  539.  
  540. \@@end
  541.  
  542.  
  543. \endinput
  544. %% 
  545. %% End of file `docstrip.tex'.
  546.